def calculate_iou(bbox1, bbox2):
     intersect_bbox = [0.,0.,0.,0.]  # bbox1和bbox2的交集
    if bbox1[2] < bbox2[0] or \
       bbox1[0] > bbox2[2] or \
       bbox1[3] < bbox2[1] or \
       bbox1[1] > bbox2[3]:
    else:
        intersect_bbox[0] = max(bbox1[0], bbox2[0])
        intersect_bbox[1] = max(bbox1[1], bbox2[1])
        intersect_bbox[2] = min(bbox1[2], bbox2[2])
        intersect_bbox[3] = min(bbox1[3], bbox2[3])

    area1 = (bbox1[2]-bbox1[0])*(bbox1[3]-bbox1[1])  # bbox1面积
    area2 = (bbox2[2] - bbox2[0]) * (bbox2[3] - bbox2[1]) bbox2面积
    area_intersect=(intersect_bbox[2]-intersect_bbox[0]) * 
                      (intersect_bbox[3]-intersect_bbox[1]) # 交集面积
    if area_intersect > 0:
        return area_intersect/(area1+area2-area_intersect) 
    # 计算iou
    else:
        return 0 
